import Vue from 'vue'
import VueRouter from "vue-router"
// import { component } from 'vue/types/umd'


Vue.use(VueRouter)

const router = new VueRouter({
    mode: 'history',
    routes: [
        {
            path: '/',
            component: () => import('@/views/Index')
        },
        {
            path: '/login',
            component: () => import('@/views/Login')
        },
        {
            path: '/reg',
            component: () => import('@/views/Register')
        },
        {
            path: '/my-order',
            component: () => import('@/views/MyOrder')
        },
        {
            path: '/my-cart',
            component: () => import('@/views/MyShoppingCart')
        },
        {
            path: '/settle',
            component: () => import('@/views/Settle')
        },
        {
            path:"/GoodsDetail",
            component: () => import('@/components/Index/IndexToDetail'),
            // props:true
        },
        {
            path:"/paySuccess",
            component:() =>import("@/components/pay/PaySuccess")
        },
        {
            path:"/zfb_t",
            component:() =>import("@/components/pay/Zfb_t")
        }
    ]
})

router.beforeEach((to, from, next) => {
    if('/' === to.path || '/GoodsDetail' === to.path || '/reg' === to.path) {
        next()
    }else if('/login' === to.path || Vue.$cookies.get('access_token')) {
    next()
    }else {
    next('/login')
    }
})


export default router